SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE view [dbo].[mayor50]
as 
select distinct tb_localidades.localidad, count(*) as mayorde50 from tb_agentes a 
inner join tb_localidades on a.localidad = idlocalidad 
where documento in(select distinct documento from Tb_LicenciasEntreFechasDeTodosLosAgentes2007 where dias  > 0 )
and documento < 13000000 group by tb_localidades.localidad 

GO
